package com.lxy.api.config;

//import com.lxy.api.client.fallback.ItemClientFallbackFactory;
import com.lxy.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {
    @Bean
    public Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }

    @Bean
    public RequestInterceptor userInfoRequestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                Long userId = UserContext.getUser();
                if(userId!=null){
                    String userInfo=userId.toString();
                    template.header("user-info", userInfo);
                }
            }
        };

    }
//TODO 降级逻辑有时间再写

//    @Bean
//    public ItemClientFallbackFactory itemClientFallbackFactory(){
//        return new ItemClientFallbackFactory();
//    }
}
